package com.example.springbootdemo09.service.impl;

import com.example.springbootdemo09.domain.Student;
import com.example.springbootdemo09.mapper.StudentMapper;
import com.example.springbootdemo09.query.StudentQuery;
import com.example.springbootdemo09.service.IStudentService;
import com.example.springbootdemo09.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class StudentServiceImpl implements IStudentService {
    @Autowired
    private StudentMapper igm;

    @Override
    public R add(Student student) {
        igm.add(student);
        return R.ok();
    }

    @Override
    public List<Student> findAll() {
        return igm.findAll();
    }

    @Override
    public Student findOne(Long id) {
        return igm.findOne(id);
    }
    @Transactional
    @Override
    public R updete(Student student) {
        igm.updete(student);
        return R.ok();
    }
    @Transactional
    @Override
    public R delete(Long id) {
        igm.delete(id);
        return R.ok();
    }

    @Override
    public R fenye(StudentQuery studentQuery) {
        Map<String, Object> map = new HashMap<>();
        Integer cont = igm.getCont(studentQuery);
        List<Student> data = igm.getData(studentQuery);
        map.put("cont", cont);
        map.put("data", data);
        return R.ok(map);
    }
    @Transactional
    @Override
    public R pathDele(Long[] id) {
        igm.pathDele(id);
        return R.ok();
    }
}
